package com.wlm.model;


import com.fasterxml.jackson.annotation.JsonInclude;


import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * <Description> Task数据结构
 *
 * @author XXX <br>
 * @version 1.0 <br>
 * @CreateDate 2018年6月12日 <br>
 * @see com.dview8.common.api.task <br>
 * @since V1.0 <br>
 */
//@Data
//@Document(collection = "DView8_Task")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Task implements Serializable {

    /**
     * serialVersionUID <br>
     */
    private static final long serialVersionUID = 1L;

    /**
     * 任务ID
     */
    private String taskId;

    /**
     * 业务资源ID
     */
    private String businessId;

    /**
     * ProbeID/coseviceId
     */
    private String probeId;

    /**
     * 任务类型
     */
    private String taskType;

    /**
     * 任务执行状态      CREATE("Create", "0"), RUN("Run", "1"), SUCCESS("Success", "2"), FAILED("Failed", "3"),
     * TIMEOUT("TimeOut", "4"), PARTIAL_SUCCESS("PartialSuccess", "5"), END("END",""6);
     */
    private String taskStatus;

    /**
     * 运行状态
     */
    private String runStatus;

    /**
     * 执行时间
     */
    private Date executeTime;

    /**
     * 过期时间
     */
    private Date expireTime;

    /**
     * 删除时间
     */
    private String deleteTime;

    /**
     * 任务内容
     */
    private String context;
    
    /**
     * 任务内容
     */
    private byte[] contextArray;

    /**
     * 任务结果
     */
    private String result;
    
    /**
     * 任务结果
     */
    private byte[] resultArray;

    /**
     * 错误码
     */
    private int errorCode;

    /**
     * 错误信息
     */
    private String errorMessage;
    
    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;
    
    /**
     * 业务版本编号
     */
    private Long taskVersion;
    
    /**
     * 扩展属性，时间戳
     */
    private long extTimestamp;


    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public String getProbeId() {
        return probeId;
    }

    public void setProbeId(String probeId) {
        this.probeId = probeId;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(String taskStatus) {
        this.taskStatus = taskStatus;
    }

    public String getRunStatus() {
        return runStatus;
    }

    public void setRunStatus(String runStatus) {
        this.runStatus = runStatus;
    }

    public Date getExecuteTime() {
        return executeTime;
    }

    public void setExecuteTime(Date executeTime) {
        this.executeTime = executeTime;
    }

    public Date getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    public String getDeleteTime() {
        return deleteTime;
    }

    public void setDeleteTime(String deleteTime) {
        this.deleteTime = deleteTime;
    }

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    public byte[] getContextArray() {
        return contextArray;
    }

    public void setContextArray(byte[] contextArray) {
        this.contextArray = contextArray;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public byte[] getResultArray() {
        return resultArray;
    }

    public void setResultArray(byte[] resultArray) {
        this.resultArray = resultArray;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Long getTaskVersion() {
        return taskVersion;
    }

    public void setTaskVersion(Long taskVersion) {
        this.taskVersion = taskVersion;
    }

    public long getExtTimestamp() {
        return extTimestamp;
    }

    public void setExtTimestamp(long extTimestamp) {
        this.extTimestamp = extTimestamp;
    }

    public List<String> getHandlerIds() {
        return handlerIds;
    }

    public void setHandlerIds(List<String> handlerIds) {
        this.handlerIds = handlerIds;
    }

    /**
     * 任务处理者(CoreServerId)
     */
    private List<String> handlerIds;
    
    public Task() {

        this.setCreateTime(new Date());
    }

    public Task(String taskId, String probeId, String taskType, String taskStatus, String runStatus, Date executeTime,
                Date expireTime, String context) {
        super();
        this.taskId = taskId;
        this.probeId = probeId;
        this.taskType = taskType;
        this.taskStatus = taskStatus;
        this.runStatus = runStatus;
        this.setExecuteTime(executeTime);
        this.setExpireTime(expireTime);
        this.setCreateTime(new Date());
        this.context = context;
    }

    public Task(String taskId, String probeId, String taskType, String taskStatus, String runStatus, Date executeTime,
                Date expireTime, String context, String result) {
        super();
        this.taskId = taskId;
        this.probeId = probeId;
        this.taskType = taskType;
        this.taskStatus = taskStatus;
        this.runStatus = runStatus;
        this.setExecuteTime(executeTime);
        this.setExpireTime(expireTime);
        this.setCreateTime(new Date());
        this.context = context;
        this.result = result;
    }

    
    /**
     * Description: 简化的Task信息<br>
     *  
     * @author GC<br>
     * @return <br>
     */
    public String toSimpleString() {
        StringBuffer sb = new StringBuffer();
        sb.append("taskId:" + this.getTaskId()).append(", ");
        sb.append("taskType:" + this.getTaskType()).append(", ");
        sb.append("taskStatus:" + this.getTaskStatus()).append(", ");
        sb.append("taskVersion:" + this.getTaskVersion()).append(", ");
        sb.append("businessId:" + this.getBusinessId()).append(", ");
        sb.append("probeId:" + this.getProbeId()).append(", ");
        sb.append("runStatus:" + this.getRunStatus()).append(", ");
        sb.append("createTime:" + this.getCreateTime()).append(", ");
        sb.append("expireTime:" + this.getExpireTime());
        long resultLength = this.getResult().length();

        sb.append("result length:" + resultLength);
        return sb.toString();
    }

}
